package com.horse.pack.service.impl;

import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.horse.pack.common.constant.HttpConstant;
import com.horse.pack.model.req.QueryActiveOrderReq;
import com.horse.pack.model.res.ProductClassifyRes;
import com.horse.pack.model.res.ProductDetailRes;
import com.horse.pack.model.res.ProductRes;
import com.horse.pack.service.KfcApp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author yangliu
 * @date 2024/3/22 3:39 PM
 */
@Service
@Slf4j
public class KfcAppImpl implements KfcApp {

    @Override
    public void queryOrder() {

    }

    @Override
    public String queryActiveOrder() {
       return null;
    }

    @Override
    public List<ProductRes> queryProductClassify(String storeCode, Integer type, Integer deliverType) {
        String url = HttpConstant.ORI_TEST_URL.concat(HttpConstant.GET_MENU_AND_PRODUCT_API);
        Map<String,Object> paramMap = new HashMap<>();
        paramMap.put("storeCode",storeCode);
        paramMap.put("type",type);
        paramMap.put("deliverType",deliverType);
        String res = HttpUtil.get(url,paramMap);
        log.info("====queryProductClassify==== 返回 {}",res);
        JSONObject jsonObject = JSON.parseObject(res);
        JSONObject object = (JSONObject) jsonObject.get("data");
        String objStr = object.get("products").toString();
        return JSON.parseArray(objStr,ProductRes.class);
    }

    @Override
    public List<ProductDetailRes> queryProductDetail(String storeCode, Integer type, Integer deliverType,String productId) {
        String url = HttpConstant.ORI_TEST_URL.concat(HttpConstant.GET_GET_PRODUCT_DETAIL);
        Map<String,Object> paramMap = new HashMap<>();
        paramMap.put("storeCode",storeCode);
        paramMap.put("type",type);
        paramMap.put("deliverType",deliverType);
        paramMap.put("productId",productId);
        String res = HttpUtil.get(url,paramMap);
        log.info("====queryProductDetail==== 返回 {}",res);
        JSONObject jsonObject = JSON.parseObject(res);
        JSONObject object = (JSONObject) jsonObject.get("data");
        return JSON.parseArray(object.toJSONString(),ProductDetailRes.class);
    }
}
